const jwt = require('jsonwebtoken');
const SECRETE_KEY = require('../keys/jwt-key');


class loginController
{
   async sign(ctx,next)
   {
       //使用jwt设置token:payload,
       const token =  jwt.sign({ id:ctx.user.id, name: ctx.user.name, password: ctx.user.password }, SECRETE_KEY, {
           expiresIn:24*60*60
       });
       
       ctx.body = {
           code: 0,
           data: {
               name:ctx.user.name,
               token:token
           }
       }
       await next();
    }
    
    async test(ctx, next)
    {
        await next();
    }
}

module.exports = new loginController();